<!--
 * @Author: krsea 965837746@qq.com
 * @Date: 2025-03-04 15:57:15
 * @LastEditors: krsea 965837746@qq.com
 * @LastEditTime: 2025-03-04 16:38:01
 * @FilePath: \vue3-code\2305\week3\m6props的值是对象.html
 * @Description: 
 * 
 * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件的基本使用</title>
    <!-- 引入 vue.js -->
    <script src="../js/vue.js"></script>
</head>

<body>
    <!-- div id 为 app 挂载点 -->
    <div id="app">
        <h3>父级数据：</h3>
        <p>姓名：{{ name }} 年龄: {{age}}</p>
        <my-dhy :age="age" :name="name" :love="msg"></my-dhy>
    </div>

    <!-- 定义组件模板 -->
     <template id="temp">
        <div>
            <h3>传到子组件修改后的数据</h3>
            子组件姓名:{{myname}}<br>
            子组件年龄:{{myage}}<br>
            子组件爱好:{{love}}<br>
        </div>
     </template>
    <!-- 使用 javascript 脚本 -->
    <script type="text/javascript">
        // 注册组件 全局
        Vue.component('my-dhy', {
            // ... options ...
            props: {
                name: String,
                age: Number,
                love: { 
                    type: String, 
                    default: '呼唤张冰慧'
                }
            },
            template: '#temp',
            data(){
                return{
                    myname:'小'+this.name,
                    myage:this.age-10,
                }
            },
        })
        // 创建app vue实例对象
        var app = new Vue({
            el: '#app',
            data: {
                name: '小黄',
                age: 18,
                msg: 'hello,张冰燕'
            }
        })
    </script>
</body>

</html>